<?php

/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Cmspage
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */

class Cmspage_Model_Album extends Core_Model_Item_Collection {
	protected $_parent_type = 'cmspage';
	
	protected $_owner_type = 'cmspage';
	
	protected $_children_types = array ('cmspage_photo' );
	
	protected $_collectible_type = 'cmspage_photo';
	
	public function getHref($params = array()) {
		$params = array_merge ( array ('route' => 'cmspage_profile', 'reset' => true, 'id' => $this->getCmspage ()->getIdentity () ), $params );
		$route = $params ['route'];
		$reset = $params ['reset'];
		unset ( $params ['route'] );
		unset ( $params ['reset'] );
		return Zend_Controller_Front::getInstance ()->getRouter ()->assemble ( $params, $route, $reset );
	}
	
	public function getCmspage() {
		return $this->getOwner ();
	}
	
	public function getAuthorizationItem() {
		return $this->getParent ( 'cmspage' );
	}
	
	protected function _delete() {
		// Delete all child posts
		$photoTable = Engine_Api::_ ()->getItemTable ( 'cmspage_photo' );
		$photoSelect = $photoTable->select ()->where ( 'album_id = ?', $this->getIdentity () );
		foreach ( $photoTable->fetchAll ( $photoSelect ) as $cmspagePhoto ) {
			$cmspagePhoto->delete ();
		}
		
		parent::_delete ();
	}

}